home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 January: Mac OS SDK / Dev.CD Jan 00 SDK1.toast / Development Kits / Mac OS / QuickTime / QuickTime 3 Interfaces & Libs / QTDevWin / CIncludes / fp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-21  |  30.3 KB  |  805 lines  |  [TEXT/dosa]

  1. /*
  2.      File:        fp.h
  3.  
  4.      Contains:    FPCE Floating-Point Definitions and Declarations.
  5.  
  6.      Version:    Technology:    MathLib v2
  7.                  Release:    QuickTime 3.0
  8.  
  9.      Copyright:    © 1987-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __FP__
  19. #define __FP__
  20.  
  21. #ifndef __CONDITIONALMACROS__
  22. #include <ConditionalMacros.h>
  23. #endif
  24. #ifndef __MACTYPES__
  25. #include <MacTypes.h>
  26. #endif
  27.  
  28. /********************************************************************************
  29. *                                                                               *
  30. *    A collection of numerical functions designed to facilitate a wide          *
  31. *    range of numerical programming as required by C9X.                         *
  32. *                                                                               *
  33. *    The <fp.h> declares many functions in support of numerical programming.    *
  34. *    It provides a superset of <math.h> and <SANE.h> functions.  Some           *
  35. *    functionality previously found in <SANE.h> and not in the FPCE <fp.h>      *
  36. *    can be found in this <fp.h> under the heading "__NOEXTENSIONS__".          *
  37. *                                                                               *
  38. *    All of these functions are IEEE 754 aware and treat exceptions, NaNs,      *
  39. *    positive and negative zero and infinity consistent with the floating-      *
  40. *    point standard.                                                            *
  41. *                                                                               *
  42. ********************************************************************************/
  43.  
  44.  
  45.  
  46. #if PRAGMA_ONCE
  47. #pragma once
  48. #endif
  49.  
  50. #ifdef __cplusplus
  51. extern "C" {
  52. #endif
  53.  
  54. #if PRAGMA_IMPORT
  55. #pragma import on
  56. #endif
  57.  
  58. #if PRAGMA_STRUCT_ALIGN
  59.     #pragma options align=mac68k
  60. #elif PRAGMA_STRUCT_PACKPUSH
  61.     #pragma pack(push, 2)
  62. #elif PRAGMA_STRUCT_PACK
  63.     #pragma pack(2)
  64. #endif
  65.  
  66. /********************************************************************************
  67. *                                                                               *
  68. *                            Efficient types                                    *
  69. *                                                                               *
  70. *    float_t         Most efficient type at least as wide as float              *
  71. *    double_t        Most efficient type at least as wide as double             *
  72. *                                                                               *
  73. *      CPU            float_t(bits)                double_t(bits)               *
  74. *    --------        -----------------            -----------------             *
  75. *    PowerPC          float(32)                    double(64)                   *
  76. *    68K              long double(80/96)           long double(80/96)           *
  77. *    x86              long double(80)              long double(80)              *
  78. *                                                                               *
  79. ********************************************************************************/
  80. #if TARGET_CPU_PPC
  81. typedef float                             float_t;
  82. typedef double                             double_t;
  83. #elif TARGET_CPU_68K
  84. typedef long double                     float_t;
  85. typedef long double                     double_t;
  86. #elif TARGET_CPU_X86
  87. #if NeXT
  88. typedef double                             float_t;
  89. typedef double                             double_t;
  90. #else
  91. typedef long double                     float_t;
  92. typedef long double                     double_t;
  93. #endif  /* NeXT */
  94.  
  95. #elif TARGET_CPU_MIPS
  96. typedef double                             float_t;
  97. typedef double                             double_t;
  98. #elif TARGET_CPU_ALPHA
  99. typedef double                             float_t;
  100. typedef double                             double_t;
  101. #elif TARGET_CPU_SPARC
  102. typedef double                             float_t;
  103. typedef double                             double_t;
  104. #else
  105. #error unsupported CPU
  106. #endif  /* TARGET_CPU_SPARC */
  107.  
  108.  
  109. /********************************************************************************
  110. *                                                                               *
  111. *                              Define some constants.                           *
  112. *                                                                               *
  113. *    HUGE_VAL            IEEE 754 value of infinity.                            *
  114. *    INFINITY            IEEE 754 value of infinity.                            *
  115. *    NAN                 A generic NaN (Not A Number).                          *
  116. *    DECIMAL_DIG         Satisfies the constraint that the conversion from      *
  117. *                        double to decimal and back is the identity function.   *
  118. *                                                                               *
  119. ********************************************************************************/
  120.  
  121. #if TARGET_OS_UNIX
  122. #define        NAN                        sqrt(-1)
  123. #else
  124. #define      HUGE_VAL                  __inf()
  125. #define      INFINITY                  __inf()
  126. #define      NAN                       nan("255")
  127. #endif
  128.  
  129. #if TARGET_CPU_PPC
  130.     #define      DECIMAL_DIG              17 /* does not exist for double-double */
  131. #elif TARGET_CPU_68K
  132.     #define      DECIMAL_DIG              21
  133. #endif      
  134.  
  135. #if TARGET_OS_MAC
  136. /********************************************************************************
  137. *                                                                               *
  138. *                            Trigonometric functions                            *
  139. *                                                                               *
  140. *   acos        result is in [0,pi].                                            *
  141. *   asin        result is in [-pi/2,pi/2].                                      *
  142. *   atan        result is in [-pi/2,pi/2].                                      *
  143. *   atan2       Computes the arc tangent of y/x in [-pi,pi] using the sign of   *
  144. *               both arguments to determine the quadrant of the computed value. *
  145. *                                                                               *
  146. ********************************************************************************/
  147. EXTERN_API_C( double_t ) cos(double_t x);
  148.  
  149. EXTERN_API_C( double_t ) sin(double_t x);
  150.  
  151. EXTERN_API_C( double_t ) tan(double_t x);
  152.  
  153. EXTERN_API_C( double_t ) acos(double_t x);
  154.  
  155. EXTERN_API_C( double_t ) asin(double_t x);
  156.  
  157. EXTERN_API_C( double_t ) atan(double_t x);
  158.  
  159. EXTERN_API_C( double_t ) atan2(double_t y, double_t x);
  160.  
  161.  
  162.  
  163. /********************************************************************************
  164. *                                                                                *
  165. *                              Hyperbolic functions                             *
  166. *                                                                                *
  167. ********************************************************************************/
  168. EXTERN_API_C( double_t ) cosh(double_t x);
  169.  
  170. EXTERN_API_C( double_t ) sinh(double_t x);
  171.  
  172. EXTERN_API_C( double_t ) tanh(double_t x);
  173.  
  174. EXTERN_API_C( double_t ) acosh(double_t x);
  175.  
  176. EXTERN_API_C( double_t ) asinh(double_t x);
  177.  
  178. EXTERN_API_C( double_t ) atanh(double_t x);
  179.  
  180.  
  181.  
  182. /********************************************************************************
  183. *                                                                                *
  184. *                              Exponential functions                               *
  185. *                                                                                *
  186. *    expm1        expm1(x) = exp(x) - 1.  But, for small enough arguments,          *
  187. *                expm1(x) is expected to be more accurate than exp(x) - 1.        *
  188. *    frexp        Breaks a floating-point number into a normalized fraction       *
  189. *                and an integral power of 2.  It stores the integer in the       *
  190. *                object pointed by *exponent.                                    *
  191. *    ldexp        Multiplies a floating-point    number by an integer power of 2.    *
  192. *    log1p        log1p = log(1 + x). But, for small enough arguments,              *
  193. *                 log1p is expected to be more accurate than log(1 + x).          *
  194. *    logb        Extracts the exponent of its argument, as a signed integral        *
  195. *                  value. A subnormal argument is treated as though it were first    *
  196. *                  normalized. Thus:                                                *
  197. *                                     1   <=   x * 2^(-logb(x))   <   2             *
  198. *    modf        Returns fractional part of x as function result and returns     *
  199. *                integral part of x via iptr. Note C9X uses double not double_t.    *
  200. *    scalb        Computes x * 2^n efficently.  This is not normally done by        *
  201. *                  computing 2^n explicitly.                                         *
  202. *                                                                                *
  203. ********************************************************************************/
  204. EXTERN_API_C( double_t ) exp(double_t x);
  205.  
  206. EXTERN_API_C( double_t ) expm1(double_t x);
  207.  
  208. EXTERN_API_C( double_t ) exp2(double_t x);
  209.  
  210. EXTERN_API_C( double_t ) frexp(double_t x, int *exponent);
  211.  
  212. EXTERN_API_C( double_t ) ldexp(double_t x, int n);
  213.  
  214. EXTERN_API_C( double_t ) log(double_t x);
  215.  
  216. EXTERN_API_C( double_t ) log2(double_t x);
  217.  
  218. EXTERN_API_C( double_t ) log1p(double_t x);
  219.  
  220. EXTERN_API_C( double_t ) log10(double_t x);
  221.  
  222. EXTERN_API_C( double_t ) logb(double_t x);
  223.  
  224. EXTERN_API_C( long double ) modfl(long double x, long double *iptrl);
  225.  
  226. EXTERN_API_C( double_t ) modf(double_t x, double_t *iptr);
  227.  
  228. EXTERN_API_C( float ) modff(float x, float *iptrf);
  229.  
  230. EXTERN_API_C( double_t ) scalb(double_t x, long n);
  231.  
  232.  
  233.  
  234. /********************************************************************************
  235. *                                                                                *
  236. *                     Power and absolute value functions                          *
  237. *                                                                                *
  238. *    hypot        Computes the square root of the sum of the squares of its        *
  239. *                  arguments, without undue overflow or underflow.                 *
  240. *    pow            Returns x raised to the power of y.  Result is more accurate    *
  241. *                than using exp(log(x)*y).                                        *
  242. *                                                                                *
  243. ********************************************************************************/
  244. EXTERN_API_C( double_t ) fabs(double_t x);
  245.  
  246. EXTERN_API_C( double_t ) hypot(double_t x, double_t y);
  247.  
  248. EXTERN_API_C( double_t ) pow(double_t x, double_t y);
  249.  
  250. EXTERN_API_C( double_t ) sqrt(double_t x);
  251.  
  252.  
  253.  
  254. /********************************************************************************
  255. *                                                                                 *
  256. *                        Gamma and Error functions                               *
  257. *                                                                                 *
  258. *     erf            The error function.                                             *
  259. *     erfc        Complementary error function.                                      *
  260. *     gamma        The gamma function.                                                *
  261. *     lgamma        Computes the base-e logarithm of the absolute value of            *
  262. *                 gamma of its argument x, for x > 0.                                *
  263. *                                                                                 *
  264. ********************************************************************************/
  265. EXTERN_API_C( double_t ) erf(double_t x);
  266.  
  267. EXTERN_API_C( double_t ) erfc(double_t x);
  268.  
  269. EXTERN_API_C( double_t ) gamma(double_t x);
  270.  
  271. EXTERN_API_C( double_t ) lgamma(double_t x);
  272.  
  273.  
  274.  
  275. /********************************************************************************
  276. *                                                                                 *
  277. *                        Nearest integer functions                                 *
  278. *                                                                                 *
  279. *     rint        Rounds its argument to an integral value in floating point         *
  280. *                  format, honoring the current rounding direction.                   *
  281. *                                                                                 *
  282. *     nearbyint    Differs from rint only in that it does not raise the inexact    *
  283. *               exception. It is the nearbyint function recommended by the        *
  284. *                  IEEE floating-point standard 854.                                  *
  285. *                                                                                 *
  286. *     rinttol        Rounds its argument to the nearest long int using the current     *
  287. *                  rounding direction.  NOTE: if the rounded value is outside        *
  288. *                the range of long int, then the result is undefined.              *
  289. *                                                                                  *
  290. *     round        Rounds the argument to the nearest integral value in floating     *
  291. *                  point format similar to the Fortran "anint" function. That is:  *
  292. *                  add half to the magnitude and chop.                             *
  293. *                                                                                 *
  294. *     roundtol    Similar to the Fortran function nint or to the Pascal round.    *
  295. *                 NOTE: if the rounded value is outside the range of long int,    *
  296. *                  then the result is undefined.                                      *
  297. *                                                                                 *
  298. *     trunc        Computes the integral value, in floating format, nearest to        *
  299. *                 but no larger in magnitude than its argument.      NOTE: on 68K    *
  300. *                compilers when using -elems881, trunc must return an int        *
  301. *                                                                                 *
  302. ********************************************************************************/
  303. EXTERN_API_C( double_t ) ceil(double_t x);
  304.  
  305. EXTERN_API_C( double_t ) floor(double_t x);
  306.  
  307. EXTERN_API_C( double_t ) rint(double_t x);
  308.  
  309. EXTERN_API_C( double_t ) nearbyint(double_t x);
  310.  
  311. EXTERN_API_C( long ) rinttol(double_t x);
  312.  
  313. EXTERN_API_C( double_t ) round(double_t x);
  314.  
  315. EXTERN_API_C( long ) roundtol(double_t round);
  316.  
  317. #if TARGET_CPU_68K
  318. EXTERN_API_C( int ) trunc(double_t x);
  319.  
  320. #else
  321. EXTERN_API_C( double_t ) trunc(double_t x);
  322.  
  323. #endif  /* TARGET_CPU_68K */
  324.  
  325.  
  326. /********************************************************************************
  327. *                                                                                 *
  328. *                            Remainder functions                                   *
  329. *                                                                                 *
  330. *     remainder        IEEE 754 floating point standard for remainder.                *
  331. *     remquo            SANE remainder.  It stores into 'quotient' the 7 low-order    *
  332. *                    bits of the integer quotient x/y, such that:                *
  333. *                        -127 <= quotient <= 127.                                 *
  334. *                                                                                 *
  335. ********************************************************************************/
  336. EXTERN_API_C( double_t ) fmod(double_t x, double_t y);
  337.  
  338. EXTERN_API_C( double_t ) remainder(double_t x, double_t y);
  339.  
  340. EXTERN_API_C( double_t ) remquo(double_t x, double_t y, int *quo);
  341.  
  342.  
  343.  
  344. /********************************************************************************
  345. *                                                                                 *
  346. *                             Auxiliary functions                               *
  347. *                                                                                 *
  348. *     copysign        Produces a value with the magnitude of its first argument    *
  349. *                      and sign of its second argument.  NOTE: the order of the     *
  350. *                      arguments matches the recommendation of the IEEE 754         *
  351. *                    floating point standard,  which is opposite from the SANE    *
  352. *                    copysign function.                                             *
  353. *                                                                                 *
  354. *     nan                The call 'nan("n-char-sequence")' returns a quiet NaN         *
  355. *                      with content indicated through tagp in the selected         *
  356. *                    data type format.                                              *
  357. *                                                                                *
  358. *     nextafter        Computes the next representable value after 'x' in the         *
  359. *                    direction of 'y'.  if x == y, then y is returned.            *
  360. *                                                                                 *
  361. ********************************************************************************/
  362. EXTERN_API_C( double_t ) copysign(double_t x, double_t y);
  363.  
  364. EXTERN_API_C( long double ) nanl(const char *tagp);
  365.  
  366. EXTERN_API_C( double ) nan(const char *tagp);
  367.  
  368. EXTERN_API_C( float ) nanf(const char *tagp);
  369.  
  370. EXTERN_API_C( long double ) nextafterl(long double x, long double y);
  371.  
  372. EXTERN_API_C( double ) nextafterd(double x, double y);
  373.  
  374. EXTERN_API_C( float ) nextafterf(float x, float y);
  375.  
  376.  
  377.  
  378. /********************************************************************************
  379. *                                                                                 *
  380. *                              Inquiry macros                                   *
  381. *                                                                                 *
  382. *     fpclassify        Returns one of the FP_≈ values.                                *
  383. *     isnormal        Non-zero if and only if the argument x is normalized.          *
  384. *     isfinite        Non-zero if and only if the argument x is finite.             *
  385. *     isnan            Non-zero if and only if the argument x is a NaN.              *
  386. *     signbit            Non-zero if and only if the sign of the argument x is        *
  387. *                      negative.  This includes, NaNs, infinities and zeros.         *
  388. *                                                                                 *
  389. ********************************************************************************/
  390.  
  391. enum {
  392.     FP_SNAN                        = 0,                            /*      signaling NaN                         */
  393.     FP_QNAN                        = 1,                            /*      quiet NaN                             */
  394.     FP_INFINITE                    = 2,                            /*      + or - infinity                       */
  395.     FP_ZERO                        = 3,                            /*      + or - zero                           */
  396.     FP_NORMAL                    = 4,                            /*      all normal numbers                    */
  397.     FP_SUBNORMAL                = 5                                /*      denormal numbers                      */
  398. };
  399.  
  400. #define      fpclassify(x)    ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  401.                               __fpclassify  ( x ) :                            \
  402.                                 ( sizeof ( x ) == sizeof(double) ) ?           \
  403.                               __fpclassifyd ( x ) :                            \
  404.                               __fpclassifyf ( x ) )
  405. #define      isnormal(x)      ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  406.                               __isnormal ( x ) :                               \
  407.                                 ( sizeof ( x ) == sizeof(double) ) ?           \
  408.                               __isnormald ( x ) :                              \
  409.                               __isnormalf ( x ) )
  410. #define      isfinite(x)      ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  411.                               __isfinite ( x ) :                               \
  412.                                 ( sizeof ( x ) == sizeof(double) ) ?           \
  413.                               __isfinited ( x ) :                              \
  414.                               __isfinitef ( x ) )
  415. #define      isnan(x)         ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  416.                               __isnan ( x ) :                                  \
  417.                               ( sizeof ( x ) == sizeof(double) ) ?             \
  418.                               __isnand ( x ) :                                 \
  419.                               __isnanf ( x ) )
  420. #define      signbit(x)       ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  421.                               __signbit ( x ) :                                \
  422.                               ( sizeof ( x ) == sizeof(double) ) ?             \
  423.                               __signbitd ( x ) :                               \
  424.                               __signbitf ( x ) )
  425. EXTERN_API_C( long ) __fpclassify(long double x);
  426.  
  427. EXTERN_API_C( long ) __fpclassifyd(double x);
  428.  
  429. EXTERN_API_C( long ) __fpclassifyf(float x);
  430.  
  431. EXTERN_API_C( long ) __isnormal(long double x);
  432.  
  433. EXTERN_API_C( long ) __isnormald(double x);
  434.  
  435. EXTERN_API_C( long ) __isnormalf(float x);
  436.  
  437. EXTERN_API_C( long ) __isfinite(long double x);
  438.  
  439. EXTERN_API_C( long ) __isfinited(double x);
  440.  
  441. EXTERN_API_C( long ) __isfinitef(float x);
  442.  
  443. EXTERN_API_C( long ) __isnan(long double x);
  444.  
  445. EXTERN_API_C( long ) __isnand(double x);
  446.  
  447. EXTERN_API_C( long ) __isnanf(float x);
  448.  
  449. EXTERN_API_C( long ) __signbit(long double x);
  450.  
  451. EXTERN_API_C( long ) __signbitd(double x);
  452.  
  453. EXTERN_API_C( long ) __signbitf(float x);
  454.  
  455. EXTERN_API_C( double_t ) __inf(void );
  456.  
  457.  
  458.  
  459. /********************************************************************************
  460. *                                                                                 *
  461. *                      Max, Min and Positive Difference                         *
  462. *                                                                                 *
  463. *     fdim        Determines the 'positive difference' between its arguments:     *
  464. *                { x - y, if x > y }, { +0, if x <= y }.  If one argument is        *
  465. *                  NaN, then fdim returns that NaN.  if both arguments are NaNs,     *
  466. *                 then fdim returns the first argument.                            *
  467. *                                                                                 *
  468. *     fmax        Returns the maximum of the two arguments.  Corresponds to the    *
  469. *                max function in FORTRAN.  NaN arguments are treated as missing     *
  470. *                data.  If one argument is NaN and the other is a number, then     *
  471. *                the number is returned.  If both are NaNs then the first         *
  472. *                argument is returned.                                             *
  473. *                                                                                 *
  474. *     fmin        Returns the minimum of the two arguments.  Corresponds to the    *
  475. *                min function in FORTRAN.  NaN arguments are treated as missing     *
  476. *                data.  If one argument is NaN and the other is a number, then     *
  477. *                the number is returned.  If both are NaNs then the first         *
  478. *                argument is returned.                                            *
  479. *                                                                                 *
  480. ********************************************************************************/
  481. EXTERN_API_C( double_t ) fdim(double_t x, double_t y);
  482.  
  483. EXTERN_API_C( double_t ) fmax(double_t x, double_t y);
  484.  
  485. EXTERN_API_C( double_t ) fmin(double_t x, double_t y);
  486.  
  487.  
  488.  
  489. /*******************************************************************************
  490. *                                Constants                                     *
  491. *******************************************************************************/
  492. extern const double_t pi;
  493.  
  494.  
  495. /********************************************************************************
  496. *                                                                                 *
  497. *                              Non NCEG extensions                                *
  498. *                                                                                 *
  499. ********************************************************************************/
  500. #ifndef __NOEXTENSIONS__
  501. /********************************************************************************
  502. *                                                                                 *
  503. *                              Financial functions                              *
  504. *                                                                                 *
  505. *     compound        Computes the compound interest factor "(1 + rate)^periods"    *
  506. *                      more accurately than the straightforward computation with     *
  507. *                    the Power function.  This is SANE's compound function.      *
  508. *                                                                                 *
  509. *     annuity            Computes the present value factor for an annuity             *
  510. *                      "(1 - (1 + rate)^(-periods)) /rate" more accurately than    *
  511. *                    the straightforward computation with the Power function.     *
  512. *                    This is SANE's annuity function.                              *
  513. *                                                                                 *
  514. ********************************************************************************/
  515. EXTERN_API_C( double_t ) compound(double_t rate, double_t periods);
  516.  
  517. EXTERN_API_C( double_t ) annuity(double_t rate, double_t periods);
  518.  
  519.  
  520.  
  521. /********************************************************************************
  522. *                                                                                 *
  523. *                              Random function                                  *
  524. *                                                                                 *
  525. *     randomx            A pseudorandom number generator.  It uses the iteration:    *
  526. *                                (75*x)mod(2^31-1)                                *
  527. *                                                                                 *
  528. ********************************************************************************/
  529. EXTERN_API_C( double_t ) randomx(double_t *x);
  530.  
  531.  
  532.  
  533. /*******************************************************************************
  534. *                              Relational operator                             *
  535. *******************************************************************************/
  536. /*      relational operator      */
  537. typedef short                             relop;
  538.  
  539. enum {
  540.     GREATERTHAN                    = 0,
  541.     LESSTHAN                    = 1,
  542.     EQUALTO                        = 2,
  543.     UNORDERED                    = 3
  544. };
  545.  
  546. EXTERN_API_C( relop ) relation(double_t x, double_t y);
  547.  
  548.  
  549.  
  550. /********************************************************************************
  551. *                                                                                 *
  552. *                         Binary to decimal conversions                         *
  553. *                                                                                 *
  554. *     SIGDIGLEN    Significant decimal digits.                                        *
  555. *                                                                                 *
  556. *     decimal        A record which provides an intermediate unpacked form for        *
  557. *                programmers who wish to do their own parsing of numeric input     *
  558. *                or formatting of numeric output.                                  *
  559. *                                                                                 *
  560. *     decform        Controls each conversion to a decimal string.  The style field     *
  561. *                is either FLOATDECIMAL or FIXEDDECIMAL. If FLOATDECIMAL, the     *
  562. *                value of the field digits is the number of significant digits.  *
  563. *                  If FIXEDDECIMAL value of the field digits is the number of        *
  564. *                digits to the right of the decimal point.                         *
  565. *                                                                                 *
  566. *     num2dec        Converts a double_t to a decimal record    using a decform.        *
  567. *     dec2num        Converts a decimal record d to a double_t value.                *
  568. *     dec2str        Converts a decform and decimal to a string using a decform.        *
  569. *     str2dec        Converts a string to a decimal struct.                            *
  570. *     dec2d        Similar to dec2num except a double is returned (68k only).        *
  571. *     dec2f        Similar to dec2num except a float is returned.                    *
  572. *     dec2s        Similar to dec2num except a short is returned.                    *
  573. *     dec2l        Similar to dec2num except a long is returned.                     *
  574. *                                                                                 *
  575. ********************************************************************************/
  576. #if    TARGET_CPU_PPC
  577.     #define SIGDIGLEN      36              
  578. #elif TARGET_CPU_68K
  579.     #define SIGDIGLEN      20
  580. #endif
  581. #define      DECSTROUTLEN   80               /* max length for dec2str output */
  582. #define      FLOATDECIMAL   ((char)(0))
  583. #define      FIXEDDECIMAL   ((char)(1))
  584.  
  585.  
  586. struct decimal {
  587.     char                             sgn;                        /* sign 0 for +, 1 for - */
  588.     char                             unused;
  589.     short                             exp;                        /* decimal exponent */
  590.     struct {
  591.         unsigned char                     length;
  592.         unsigned char                     text[SIGDIGLEN];        /* significant digits */
  593.         unsigned char                     unused;
  594.     }                                 sig;
  595. };
  596. typedef struct decimal decimal;
  597.  
  598. struct decform {
  599.     char                             style;                        /*  FLOATDECIMAL or FIXEDDECIMAL */
  600.     char                             unused;
  601.     short                             digits;
  602. };
  603. typedef struct decform decform;
  604.  
  605. EXTERN_API_C( void ) num2dec(const decform *f, double_t x, decimal *d);
  606.  
  607. EXTERN_API_C( double_t ) dec2num(const decimal *d);
  608.  
  609. EXTERN_API_C( void ) dec2str(const decform *f, const decimal *d, char *s);
  610.  
  611. EXTERN_API_C( void ) str2dec(const char *s, short *ix, decimal *d, short *vp);
  612.  
  613. #if TARGET_CPU_68K
  614. EXTERN_API_C( double ) dec2d(const decimal *d);
  615.  
  616. #endif  /* TARGET_CPU_68K */
  617.  
  618. EXTERN_API_C( float ) dec2f(const decimal *d);
  619.  
  620. EXTERN_API_C( short ) dec2s(const decimal *d);
  621.  
  622. EXTERN_API_C( long ) dec2l(const decimal *d);
  623.  
  624.  
  625.  
  626.  
  627. /********************************************************************************
  628. *                                                                                 *
  629. *                         68k-only Transfer Function Prototypes                 *
  630. *                                                                                 *
  631. ********************************************************************************/
  632. #if TARGET_CPU_68K
  633. #if TARGET_RT_MAC_68881
  634. EXTERN_API_C( void ) x96tox80(const extended96 *x, extended80 *x80);
  635.  
  636. EXTERN_API_C( void ) x80tox96(const extended80 *x80, extended96 *x);
  637.  
  638. #else
  639. EXTERN_API_C( void ) x96tox80(const extended96 *x96, extended80 *x);
  640.  
  641. EXTERN_API_C( void ) x80tox96(const extended80 *x, extended96 *x96);
  642.  
  643. #endif  /* TARGET_RT_MAC_68881 */
  644.  
  645. #endif  /* TARGET_CPU_68K */
  646.  
  647. #endif  /*  ! defined(__NOEXTENSIONS__)  */
  648.  
  649. /********************************************************************************
  650. *                                                                                 *
  651. *                         PowerPC-only Function Prototypes                         *
  652. *                                                                                 *
  653. ********************************************************************************/
  654.  
  655. #if TARGET_CPU_PPC
  656. EXTERN_API_C( long double ) cosl(long double x);
  657.  
  658. EXTERN_API_C( long double ) sinl(long double x);
  659.  
  660. EXTERN_API_C( long double ) tanl(long double x);
  661.  
  662. EXTERN_API_C( long double ) acosl(long double x);
  663.  
  664. EXTERN_API_C( long double ) asinl(long double x);
  665.  
  666. EXTERN_API_C( long double ) atanl(long double x);
  667.  
  668. EXTERN_API_C( long double ) atan2l(long double y, long double x);
  669.  
  670. EXTERN_API_C( long double ) coshl(long double x);
  671.  
  672. EXTERN_API_C( long double ) sinhl(long double x);
  673.  
  674. EXTERN_API_C( long double ) tanhl(long double x);
  675.  
  676. EXTERN_API_C( long double ) acoshl(long double x);
  677.  
  678. EXTERN_API_C( long double ) asinhl(long double x);
  679.  
  680. EXTERN_API_C( long double ) atanhl(long double x);
  681.  
  682. EXTERN_API_C( long double ) expl(long double x);
  683.  
  684. EXTERN_API_C( long double ) expm1l(long double x);
  685.  
  686. EXTERN_API_C( long double ) exp2l(long double x);
  687.  
  688. EXTERN_API_C( long double ) frexpl(long double x, int *exponent);
  689.  
  690. EXTERN_API_C( long double ) ldexpl(long double x, int n);
  691.  
  692. EXTERN_API_C( long double ) logl(long double x);
  693.  
  694. EXTERN_API_C( long double ) log1pl(long double x);
  695.  
  696. EXTERN_API_C( long double ) log10l(long double x);
  697.  
  698. EXTERN_API_C( long double ) log2l(long double x);
  699.  
  700. EXTERN_API_C( long double ) logbl(long double x);
  701.  
  702. EXTERN_API_C( long double ) scalbl(long double x, long n);
  703.  
  704. EXTERN_API_C( long double ) fabsl(long double x);
  705.  
  706. EXTERN_API_C( long double ) hypotl(long double x, long double y);
  707.  
  708. EXTERN_API_C( long double ) powl(long double x, long double y);
  709.  
  710. EXTERN_API_C( long double ) sqrtl(long double x);
  711.  
  712. EXTERN_API_C( long double ) erfl(long double x);
  713.  
  714. EXTERN_API_C( long double ) erfcl(long double x);
  715.  
  716. EXTERN_API_C( long double ) gammal(long double x);
  717.  
  718. EXTERN_API_C( long double ) lgammal(long double x);
  719.  
  720. EXTERN_API_C( long double ) ceill(long double x);
  721.  
  722. EXTERN_API_C( long double ) floorl(long double x);
  723.  
  724. EXTERN_API_C( long double ) rintl(long double x);
  725.  
  726. EXTERN_API_C( long double ) nearbyintl(long double x);
  727.  
  728. EXTERN_API_C( long ) rinttoll(long double x);
  729.  
  730. EXTERN_API_C( long double ) roundl(long double x);
  731.  
  732. EXTERN_API_C( long ) roundtoll(long double round);
  733.  
  734. EXTERN_API_C( long double ) truncl(long double x);
  735.  
  736. EXTERN_API_C( long double ) remainderl(long double x, long double y);
  737.  
  738. EXTERN_API_C( long double ) remquol(long double x, long double y, int *quo);
  739.  
  740. EXTERN_API_C( long double ) copysignl(long double x, long double y);
  741.  
  742. EXTERN_API_C( long double ) fdiml(long double x, long double y);
  743.  
  744. EXTERN_API_C( long double ) fmaxl(long double x, long double y);
  745.  
  746. EXTERN_API_C( long double ) fminl(long double x, long double y);
  747.  
  748.  
  749. #ifndef __NOEXTENSIONS__
  750. EXTERN_API_C( relop ) relationl(long double x, long double y);
  751.  
  752. EXTERN_API_C( void ) num2decl(const decform *f, long double x, decimal *d);
  753.  
  754. EXTERN_API_C( long double ) dec2numl(const decimal *d);
  755.  
  756. /*    
  757.     MathLib v2 has two new transfer functions: x80tod and dtox80.  They can 
  758.     be used to directly transform 68k 80-bit extended data types to double
  759.     and back for PowerPC based machines without using the functions
  760.     x80told or ldtox80.  Double rounding may occur. 
  761. */
  762. EXTERN_API_C( void ) x80told(const extended80 *x80, long double *x);
  763.  
  764. EXTERN_API_C( void ) ldtox80(const long double *x, extended80 *x80);
  765.  
  766. EXTERN_API_C( double ) x80tod(const extended80 *x80);
  767.  
  768. EXTERN_API_C( void ) dtox80(const double *x, extended80 *x80);
  769.  
  770. #endif  /*  ! defined(__NOEXTENSIONS__)  */
  771.  
  772. #endif  /* TARGET_CPU_PPC */
  773.  
  774. #else
  775. /*
  776.     Non-Mac platforms may have long doubles.
  777. */
  778. EXTERN_API_C( void ) x80told(const extended80 *x80, long double *x);
  779.  
  780. EXTERN_API_C( void ) ldtox80(const long double *x, extended80 *x80);
  781.  
  782. #endif  /* TARGET_OS_MAC */
  783.  
  784.  
  785. #if PRAGMA_STRUCT_ALIGN
  786.     #pragma options align=reset
  787. #elif PRAGMA_STRUCT_PACKPUSH
  788.     #pragma pack(pop)
  789. #elif PRAGMA_STRUCT_PACK
  790.     #pragma pack()
  791. #endif
  792.  
  793. #ifdef PRAGMA_IMPORT_OFF
  794. #pragma import off
  795. #elif PRAGMA_IMPORT
  796. #pragma import reset
  797. #endif
  798.  
  799. #ifdef __cplusplus
  800. }
  801. #endif
  802.  
  803. #endif /* __FP__ */
  804.  
  805.